app.controller("topicController",function($scope, $controller, topicService){
    $scope.list = [];//页面显示的列表

    $scope.searchEntity = {};//搜索用的数据
    $scope.entity = {spec:{},options:[]};//编辑保存用的实体数据
    $controller("baseController",{$scope:$scope});

    $scope.list = function(){
        //去后台查询数据
        topicService.list().then(function(result){
            $scope.list = result.data;
        });
    }



    //添加一行
    $scope.addOption = function(){
        $scope.entity.options.push({});
    }
    $scope.delOption = function($index){
        $scope.entity.options.splice($index,1);
    }


    $scope.save = function(){
        if($scope.entity.topic.tid){
            topicService.update($scope.entity).then(function(result){
                if(result.data.success){
                    //刷新列表
                    location.reload();
                }else {
                    alert(result.data.message);
                }
            });
        }else{
            topicService.save($scope.entity).then(function(result){
                if(result.data.success){
                    //刷新列表
                    location.reload();
                }else {
                    alert(result.data.message);
                }
            });
        }
    }
    $scope.edit = function(tid){
        topicService.findOne(tid).then(function(result){
            $scope.entity = result.data;
        });
    }
    $scope.del = function(){
        topicService.del($scope.ids).then(function(result){
            if(result.data.success){
                //刷新列表
                location.reload();
            }else {
                alert(result.data.message);
            }
        });
    }


});